home *** CD-ROM | disk | FTP | other *** search
- static char today_prog[] = "@(#)Aktuelles Datum ermitteln";
- static char today_ver[] = "@(#)v1.10/kr ; 10.06.91";
- /* today Ermitteln des aktuellen Datums aus der Systemzeit.
- **
- ** Autor Klaus Rath
- **
- ** Deklaration char *today(int format);
- **
- ** Beschreibung Die Funktion liest die Systemzeit aus und gibt einen String
- ** im gewünschten Format zurück. Die aufrufende Funktion muß
- ** deshalb sicherstellen, daß ein char-Array ausreichender
- ** Größe definiert ist, oder sich zum Aufrufzeitpunkt genügend
- ** Speicherplatz per malloc besorgen.
- ** Erlaubte Formate, ihre Ausprägung und ihre Arraylänge:
- ** 1 tt.mm.jj 9
- ** 2 mm/tt/jj 9
- ** 3 jjmmtt 7
- ** 4 tt.mm.jjjj 11
- ** 5 mm/tt/jjjj 11
- ** 6 jjjjmmtt 9
- ** 7 tt.mm. 7
- ** 8 mm/tt 6
- ** Im Fehlerfall gibt today einen (char *)NULL zurück!
- **
- ** Änderungen 1.00 ; 12.04.91
- ** - Erste Version
- ** 1.10 ; 10.06.91
- ** - Kurzformate 7 und 8 eingebaut, Umkopieren durch sprintf()
- ** ersetzt.
- */
-
- #include <stdio.h>
- #include <time.h>
- #include <string.h>
- #include <sys\types.h>
- #ifdef __TURBOC__
- #define ANSI
- #define MSDOS
- #include <stdlib.h>
- #endif
- #include "datum.h"
-
- #ifdef ANSI
- char *today(int format)
- #else
- char *today(format)
- int format;
- #endif
- {
- char tag[3];
- char monat[3];
- char jahr[3];
- char jh[3];
- char jahreszahl[5];
- int tag_z;
- int monat_z;
- int jahr_z;
- char systemzeit_s[26];
- time_t systemzeit;
- struct tm *heute;
- char rueckgabe[11];
-
- /* Jahrhundert aus der Systemzeit ermitteln :
- */
- time(&systemzeit);
- strcpy(systemzeit_s,ctime(&systemzeit));
- jh[0] = systemzeit_s[20];
- jh[1] = systemzeit_s[21];
- jh[2] = '\0';
-
- /* Restliche Elemente aus der localtime :
- */
- heute = localtime(&systemzeit);
- tag_z = heute->tm_mday;
- monat_z = heute->tm_mon + 1;
- jahr_z = heute->tm_year;
-
- /* Formatiert umkopieren (2stellig!) :
- */
- sprintf(tag, "%02d",tag_z);
- sprintf(monat,"%02d",monat_z);
- sprintf(jahr, "%02d",jahr_z);
-
- /* Je nach Format Jahrhundert ergänzen :
- */
- if ( format >= 1 && format <= 3 ) {
- strcpy(jahreszahl,jahr);
- }
- else if ( format >= 4 && format <= 6 ) {
- strcpy(jahreszahl,jh);
- strcat(jahreszahl,jahr);
- }
- else if ( format == 7 || format == 8 ) {
- ;/* Keine Ergänzung! */
- }
- else
- return(NULL);
-
- /* Rückgabe nach Vorgabe zusammensetzen :
- */
- if ( format == DE_KURZ || format == DE_LANG ) {
- strcpy(rueckgabe,tag);
- strcat(rueckgabe,".");
- strcat(rueckgabe,monat);
- strcat(rueckgabe,".");
- strcat(rueckgabe,jahreszahl);
- }
- else if ( format == AM_KURZ || format == AM_LANG ) {
- strcpy(rueckgabe,monat);
- strcat(rueckgabe,"/");
- strcat(rueckgabe,tag);
- strcat(rueckgabe,"/");
- strcat(rueckgabe,jahreszahl);
- }
- else if ( format == DB_KURZ || format == DB_LANG ) {
- strcpy(rueckgabe,jahreszahl);
- strcat(rueckgabe,monat);
- strcat(rueckgabe,tag);
- }
- else if ( format == DE_AKTJAHR ) {
- strcpy(rueckgabe,tag);
- strcat(rueckgabe,".");
- strcat(rueckgabe,monat);
- strcat(rueckgabe,".");
- }
- else if ( format == DE_AKTJAHR ) {
- strcpy(rueckgabe,monat);
- strcat(rueckgabe,"/");
- strcat(rueckgabe,tag);
- }
- else
- return(NULL);
-
- return(rueckgabe);
-
- } /* ENDE: today() */
-